import { EventNames } from "../consts/EventNames";

export default class EventBus {
    private static emitter: EventEmitter = <any>events;//.emitter();

    public static on(eventName: EventNames, listener: (...args: any[]) => void): EventEmitter {
        return this.emitter.on(EventNames[eventName], listener);
    }

    public static once(eventName: EventNames, listener: (...args: any[]) => void): EventEmitter {
        return this.emitter.once(EventNames[eventName], listener);
    }

    public static emit(eventName: EventNames, ...args: any[]): boolean {
        return (<any>engines.myEngine()).emit(EventNames[eventName], ...args);
    }

    public static removeAllListeners(eventName?: EventNames): EventEmitter {
        return this.emitter.removeAllListeners(EventNames[eventName]);
    }

    public static removeListener(eventName: EventNames, listener: (...args: any[]) => void): EventEmitter {
        return this.emitter.removeListener(EventNames[eventName], listener);
    }
}